﻿using UnityEngine;
using System.Collections;

[RequireComponent(typeof(WheelJoint2D))]
public class Wheel : MonoBehaviour {

    public float speed = 15;

    WheelJoint2D joint;

    void Start()
    {
        joint = GetComponent<WheelJoint2D>();
    }

    public void Change(float speed)
    {
        JointMotor2D motor = new JointMotor2D();
        motor.motorSpeed = speed;
        motor.maxMotorTorque = joint.motor.maxMotorTorque;
        joint.motor = motor;
    }

	public void Left ()
    {
        joint.useMotor = true;
        Change(-speed);
	}

    public void Right()
    {
        joint.useMotor = true;
        Change(speed);
    }

    public void Stop()
    {
        joint.useMotor = false;
    }
}
